package com.pisolution.scheduler.runtime.workflow;

import com.pisolution.scheduler.datasource.instance.Priority;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 工作流中可执行计算单元数据实体.
 *
 * @author sora
 * @version 0.1.0
 */
public final class TaskNode {
    // -------------------------------------------------------------------------------------------------
    //  数据单元 (公共属性)
    // -------------------------------------------------------------------------------------------------

    /** 计算节点标识. */
    private String id;

    /** 计算节点名称. */
    private String name;

    /** 计算节点描述. */
    private String description;

    /** 计算节点适配器类型. */
    private String type;

    /** 计算节点优先级. */
    private Priority priority;

    /** 计算节点最大重试次数. */
    private int maxRetryCount;

    /** 计算节点重试间隔. */
    private int interval;

    /** 计算节点超时设置. */
    private Timeout timeout;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (私有属性)
    // -------------------------------------------------------------------------------------------------

    /** 计算节点属性. */
    private TaskNodeProperty properties;

    // -------------------------------------------------------------------------------------------------
    //  数据单元 (来自交互)
    // -------------------------------------------------------------------------------------------------

    /** 计算节点之间的连线. */
    private Map<String, PropertySource> connections;

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public String getName() {
        return this.name;
    }

    public String getType() {
        return this.type;
    }

    public Priority getPriority() {
        return this.priority;
    }

    public int getMaxRetryCount() {
        return this.maxRetryCount;
    }

    public int getInterval() {
        return this.interval;
    }

    public Timeout getTimeout() {
        return this.timeout;
    }

    public Map<String, PropertySource> getConnections() {
        return this.connections;
    }

    public List<String> getDependentNodes() {
        return this.connections.values().stream().map(PropertySource::getName).distinct().collect(Collectors.toList());
    }
}
